package com.example.zk1;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.zk1.adapter.FragAdapter;
import com.example.zk1.bean.CommBean;
import com.example.zk1.fragment.OneFragment;
import com.example.zk1.fragment.TwoFragment;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;


public class ZhuActivity extends AppCompatActivity {
//    private TabLayout tab;
    private ViewPager vp;
    private TextView zi;
    private Button dian;
    private CommonTabLayout tab;
    private ArrayList<CustomTabEntity> mtabEntitys = new ArrayList<>();
    private List<Fragment>list=new ArrayList<>();
    FragAdapter fragAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu);

       // tab = (TabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);
        zi = (TextView) findViewById(R.id.zi);
        dian = (Button) findViewById(R.id.dian);
        tab = (CommonTabLayout) findViewById(R.id.tab);
        mtabEntitys.add(new CommBean("推荐",R.drawable.select_1,R.drawable.default_1));
        mtabEntitys.add(new CommBean("同城",R.drawable.select_1,R.drawable.default_1));
        tab.setTabData(mtabEntitys);





        OneFragment oneFragment = new OneFragment();
        TwoFragment twoFragment = new TwoFragment();
        list.add(oneFragment);
        list.add(twoFragment);

       fragAdapter=new FragAdapter(getSupportFragmentManager(),list);
       vp.setAdapter(fragAdapter);
       tab.setOnTabSelectListener(new OnTabSelectListener() {
           @Override
           public void onTabSelect(int position) {
               if(position==0){
                   vp.setCurrentItem(0);
               }else if(position==1){
                   vp.setCurrentItem(1);
               }
           }

           @Override
           public void onTabReselect(int position) {

           }
       });


        dian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                zi.setTextColor(Color.RED);
                zi.setTextSize(30);
            }
        });

    }
}
